import 'package:cbec_app/components/base/base_image.dart';
import 'package:flutter/material.dart';
import '../../pages/home/view/index_page.dart';
import '../../pages/classify/view/classify_page.dart';
import '../../pages/member/view/member_page.dart';
import '../../pages/bags/view/bags_page.dart';
import '../../pages/my/view/my_page.dart';

///导航栏类型
enum BottomNavBarType {
  ///首页
  home,

  ///分类
  classify,

  ///会员
  member,

  ///购物袋
  bags,

  ///我的
  my
}

///底部导航栏扩展
extension BottomNavBarTypeExt on BottomNavBarType {
  ///图标宽高
  double get imageWH {
    return 20;
  }

  /// 页面
  Widget getPage({bool allowMember = false}) {
    final pages = {
      BottomNavBarType.home: const IndexPage(),
      BottomNavBarType.classify: const ClassifyPage(),
      if (allowMember) BottomNavBarType.member: const MemberPage(),
      BottomNavBarType.bags: BagsPage(),
      BottomNavBarType.my: MyPage(),
    };

    return pages[this] ?? const SizedBox.shrink(); // 默认返回空视图以防止未匹配情况
  }

  ///导航栏item
  /// 导航栏 item 列表，根据是否过滤会员类型生成不同列表
  static List<BottomNavigationBarItem> getItems({bool allowMember = false}) {
    return BottomNavBarType.values
        .where((type) => allowMember || type != BottomNavBarType.member) // 过滤条件
        .map(
          (type) => BottomNavigationBarItem(
            icon: type.defaultIcon,
            activeIcon: type.activeIcon,
            label: type.title,
          ),
        )
        .toList();
  }

  ///默认图标
  Widget get defaultIcon {
    switch (this) {
      case BottomNavBarType.home:
        return BaseImage(url: 'index_default.png', width: imageWH, height: imageWH);
      case BottomNavBarType.classify:
        return BaseImage(url: 'classify_default.png', width: imageWH, height: imageWH);
      case BottomNavBarType.member:
        return BaseImage(url: 'member_default.png', width: imageWH, height: imageWH);
      case BottomNavBarType.bags:
        return BaseImage(url: 'bags_default.png', width: imageWH, height: imageWH);
      case BottomNavBarType.my:
        return BaseImage(url: 'my_default.png', width: imageWH, height: imageWH);
    }
  }

  ///激活图标
  Widget get activeIcon {
    switch (this) {
      case BottomNavBarType.home:
        return BaseImage(url: 'index_active.png', width: imageWH, height: imageWH);
      case BottomNavBarType.classify:
        return BaseImage(url: 'classify_active.png', width: imageWH, height: imageWH);
      case BottomNavBarType.member:
        return BaseImage(url: 'member_active.png', width: imageWH, height: imageWH);
      case BottomNavBarType.bags:
        return BaseImage(url: 'bags_active.png', width: imageWH, height: imageWH);
      case BottomNavBarType.my:
        return BaseImage(url: 'my_active.png', width: imageWH, height: imageWH);
    }
  }

  ///标题
  String get title {
    switch (this) {
      case BottomNavBarType.home:
        return '首页';
      case BottomNavBarType.classify:
        return '分类';
      case BottomNavBarType.member:
        return '会员';
      case BottomNavBarType.bags:
        return '购物车';
      case BottomNavBarType.my:
        return '我的';
    }
  }
}
